home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / xpk_source / xpkmaster / hook.c < prev    next >
C/C++ Source or Header  |  1998-08-27  |  2KB  |  78 lines

  1. #ifndef XPKMASTER_HOOK_C
  2. #define XPKMASTER_HOOK_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        hook.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: hook.c 1.4 (26.08.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Hook handling functions
  12.  
  13.  1.0   05.10.96 : first real version
  14.  1.1   27.12.96 : removed V37 defines
  15.  1.2   20.12.97 : nearly rewritten
  16.  1.3   09.01.98 : added XPK_ALLINONE
  17.  1.4   26.08.98 : returns XPKERR_BADPARAMS, when no hook exists
  18. */
  19.  
  20. #include <exec/types.h>
  21. #include "xpkmaster.h"
  22.  
  23. #ifdef DEBUG
  24. static STRPTR action_names[8] =
  25. {"<zero>", "XIO_READ", "XIO_WRITE", "XIO_FREE", "XIO_ABORT", "XIO_GETBUF",
  26. "XIO_SEEK", "XIO_TOTSIZE" };
  27. #endif
  28.  
  29. static APTR callhook(struct XpkBuffer *xbuf, ULONG action, APTR buf,
  30. ULONG size, struct XpkMasterMsg *msg, struct Hook *hook)
  31. {
  32.   LONG res;
  33.  
  34.   msg->xmm_Type = action;
  35.   msg->xmm_Ptr = (STRPTR) buf;
  36.   msg->xmm_Size = size;
  37.  
  38.   if(!hook)
  39.   {
  40.     xbuf->xb_Result = XPKERR_BADPARAMS;
  41.     return 0;
  42.   }
  43.  
  44.   if((res = (*(regfunc) hook->h_Entry) (hook, msg, 0 A4SUPP2)))
  45.   {
  46.     xbuf->xb_Result = res;
  47. #ifdef DEBUG
  48.     DebugError("hook%s: %s <%ld> (%ld)", msg == &xbuf->xb_RMsg ? "read" :
  49.     "write", action_names[(action&7)], action, xbuf->xb_Result);
  50. #endif
  51.   }
  52.  
  53.   if(xbuf->xb_Result)
  54.     return 0;
  55.   else if(msg->xmm_Ptr)
  56.     return (APTR) msg->xmm_Ptr;
  57.   else
  58.     return (APTR) -1; /* SEEK may return 0 on success! */
  59. }
  60.  
  61. /*************************** read from input hook ************************/
  62.  
  63. XPK_ALLINONE APTR hookread(struct XpkBuffer *xbuf, ULONG action, APTR buf,
  64. ULONG size)
  65. {
  66.   return callhook(xbuf, action, buf, size, &xbuf->xb_RMsg, xbuf->xb_RHook);
  67. }
  68.  
  69. /*************************** write to output hook ************************/
  70.  
  71. XPK_ALLINONE APTR hookwrite(struct XpkBuffer *xbuf, ULONG action, APTR buf,
  72. ULONG size)
  73. {
  74.   return callhook(xbuf, action, buf, size, &xbuf->xb_WMsg, xbuf->xb_WHook);
  75. }
  76.  
  77. #endif /* XPKMASTER_HOOK_C */
  78.